package top.dreamyy.pattern.controller;


import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import top.dreamyy.pattern.domain.Pattern;
import top.dreamyy.pattern.service.PatternService;


@Controller
public class PatternController {
	/**
	 * 自动注入
	 */
	@Autowired
	@Qualifier("patternService")
	private PatternService patternService;
	
	
	/**
	 * 
	 * @param id   名称一样的话  自动注入?
	 * @param model
	 * @return
	 */
	@RequestMapping("/patternOption")
	public String FindPattern(
			String flag,
			Model model){
		int id = Integer.parseInt(flag);
		Pattern pattern = patternService.select(id);
		model.addAttribute("pattern", pattern);
		return "pattern/pattern"+id;
		
	}
	
	
	@RequestMapping("/suggestController")
	public void SaveSuggest(String text,HttpServletResponse response){
		try {
			PrintWriter out=response.getWriter();
			int n = patternService.saveSugg(text);
			System.out.println("  "+n);
			out.print(n);
			System.out.println("进入建议controller");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
}
